import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class FlutterWebViewPluginPage extends StatefulWidget{

  @override
  State<StatefulWidget> createState() => _FlutterWebViewPluginState();

}

class _FlutterWebViewPluginState extends State<FlutterWebViewPluginPage> {

  FlutterWebviewPlugin flutterWebviewPlugin = FlutterWebviewPlugin();
  double progress = 0.0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    flutterWebviewPlugin.onProgressChanged.listen((progress) {
      setState(() {
        this.progress = progress;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return WebviewScaffold(
      appBar: AppBar(
        title: Text("Flutter WebView Plugin"),
        bottom: PreferredSize(
          child: Container(
            child: LinearProgressIndicator(
              backgroundColor: Colors.white70.withOpacity(0),
              value: progress == 1.0 ? 0 : progress,
              valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
            ),
            height: 2,
          ),
        ),
      ),
      url: "https://flutterchina.club/",
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    flutterWebviewPlugin.dispose();
    super.dispose();
  }

}